﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HKEA.CMS.Core.BLL;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.Utility;
using System.Web.SessionState;
using HKEA.CMS.Core.BLL.Mtbl;
using HKEA.CMS.Core.BLL.Tbl;
namespace WebApplication.ServerAshxFile
{
    /// <summary>
    /// DeleteBrand 的摘要说明
    /// </summary>
    public class DeleteBrand : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            int customeruid = 0;
            int branduid = 0;
            int.TryParse(context.Request.QueryString["CUID"],out customeruid);
            int.TryParse(context.Request.QueryString["CBUID"],out branduid);
            string str = string.Empty;
            if (customeruid > 0 && branduid > 0)
            {
                int i = 0;
                mtblBrand brandENT = new mtblBrand();
                mtblBrandBLL brandBLL = new mtblBrandBLL();
                brandENT.CustomerUID = customeruid;
                brandENT.BrandUID = branduid;
                brandENT = brandBLL.GetEntity(brandENT);
                if (brandENT != null)
                {
                    if (brandENT.Deleted == 0)
                    {
                        brandENT.Deleted = 1;
                        if (brandBLL.UpdateENT(brandENT) > 0)
                        {
                            str = "{\"Issucess\":\"1\",\"Meg\":\"" + ResourceManage.GetResourceString("msg200011") + "\"}";
                            WriteToLoge(customeruid, brandENT.BrandName_Eng);
                        }
                        else
                        { str = "{\"Issucess\":\"0\",\"Meg\":\"" + ResourceManage.GetResourceString("msg200010") + "\"}"; }
                    }
                    else
                    { str = "{\"Issucess\":\"0\",\"Meg\":\"" + ResourceManage.GetResourceString("msg200014") + "\"}"; }
                }
                else
                { str = "{\"Issucess\":\"0\",\"Meg\":\"" + ResourceManage.GetResourceString("msg200014") + "\"}"; }
            }
            else
            { str = "{\"Issucess\":\"0\",\"Meg\":\"" + ResourceManage.GetResourceString("msg200001") + "\"}"; }

            context.Response.Write(str);
            context.Response.Flush();
            
        }
        protected void WriteToLoge(int customerUID ,string BrandName) { 
            tblHistory entlog = new tblHistory();
            BasePage page = new BasePage();
            tblCustomer Company = tblCustomerBLL.GetInstance().GetEntity(customerUID);
            tblUser ent = page.GetManageFromSession();
            entlog.HistoryCatUID = 2;
            entlog.HistoryTypeUID = 27;
            entlog.CustomerUID = customerUID;
            entlog.Cust_MemberUID = 0;
            entlog.ContactPersonUID = 0;
            entlog.History_Detail = ent.User_Name + " {" + Company.Name_Eng + "}{Brand}Delete " + BrandName;
            entlog.LastModifyBy = ent.User_Name;
            int tal = HKEA.CMS.Core.BLL.Tbl.tblHistoryBLL.GetInstance().InsertENT(entlog);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}